package com.itheima.app.controller;

import com.itheima.app.interceptor.UserHolder;
import com.itheima.app.manager.MessageManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

@RestController
public class MessageController {

    @Autowired
    private MessageManager messageManager;

    // 获取探花app的（id+pwd）
    @GetMapping("/huanxin/user")
    public ResponseEntity huanxinUser() {
        // 1.获取登录用户的userId
        Long userId = UserHolder.get().getId();
        // 2.组装返回结果
        Map<String, String> result = new HashMap<>();
        result.put("username", String.valueOf(userId));
        result.put("password", "123456");
        // 3.返回结果
        return ResponseEntity.ok(result);
    }

    // 聊一下（回复陌生人问题）
    @PostMapping("/tanhua/strangerQuestions")
    public void liaoYiXia(@RequestBody Map<String, String> map) {
        // 接收参数
        long jiarenId = Long.parseLong(map.get("userId"));
        String reply = map.get("reply");
        // 调用manager
        messageManager.liaoYiXia(jiarenId, reply);

    }

    // 添加好友
    @PostMapping("/messages/contacts")
    public void addContacts(@RequestBody Map<String, Long> map) {
        // 接收参数
        Long friendId = map.get("userId");
        // 调用manager
        messageManager.addContacts(friendId);
    }

    // 查询好友列表
    @GetMapping("/messages/contacts")
    public ResponseEntity findContacts(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        // 调用manager
        return messageManager.findContacts(pageNum, pageSize);
    }

    // 点赞人信息
    @GetMapping("/messages/likes")
    public ResponseEntity findLikeUser(@RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                       @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        // 确定操作类型
        Integer commentType = 1;
        // 调用manager
        return messageManager.findUserCommentVo(commentType, pageNum, pageSize);

    }
    // 评论人信息
    @GetMapping("/messages/comments")
    public ResponseEntity findCommentUser(@RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                       @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        // 确定操作类型
        Integer commentType = 2;
        // 调用manager
        return messageManager.findUserCommentVo(commentType, pageNum, pageSize);

    }

    // 喜欢人信息
    @GetMapping("/messages/loves")
    public ResponseEntity findLoveUser(@RequestParam(value = "page", defaultValue = "1") Integer pageNum,
                                          @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        // 确定操作类型
        Integer commentType = 3;
        // 调用manager
        return messageManager.findUserCommentVo(commentType, pageNum, pageSize);

    }
}
